<%@ page language="java" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%
Object obj=request.getSession().getAttribute("role_resource");
if(null==obj){
	response.setStatus(1000);
	return;
}
%> 
	<script type="text/javascript">
		//外包商状态下拉列表
		var state_store = new Ext.data.JsonStore({
			fields : [ "id", "text" ],
			data : [ {
				id : "0",
				text : "禁用"
			}, {
				id : "1",
				text : "启用"
			}]
		});
		//外包商列表数据源
		var data_store = new Ext.data.JsonStore({
			root: "data",
        	totalProperty: "total",
			fields: ["id", "name", "linkman", "linkphone","linkaddr", "state",
					"ftp", "port", "ftpuser", "ftppass", "ftppath", "remark"],
        	url: "epiboly!list.action"
    	});
		
		//定义数据显示面板
		var p1 = {
			id: "p1",
			xtype: "grid",
			stripeRows: true,
			loadMask: true,
			autoExpandColumn: "remark",
			autoExpandMin: 100,
			store: data_store,
			headersDisabled: true,
			columns:[
    	    	new Ext.grid.RowNumberer({header: "序号", width: 35}),
   					{header: "编号",			dataIndex: "id", menuDisabled: true},
   					{header: "名称",			dataIndex: "name", menuDisabled: true},
   					{header: "联系人",		dataIndex: "linkman", menuDisabled: true},
   					{header: "联系电话",		dataIndex: "linkphone", menuDisabled: true},
   					{header: "联系地址",		dataIndex: "linkaddr", menuDisabled: true},
   					{header: "状态",			dataIndex: "state", menuDisabled: true,
    					renderer:function(input){
	   						 if(""==input)return input;
	            			 var res2=state_store.getById(input);
							 return res2.data.text;
            		  	}
            		},
   					{header: "FTP地址",		dataIndex: "ftp", menuDisabled: true},
   					{header: "FTP端口",		dataIndex: "port", menuDisabled: true},
   					{header: "FTP用户名",	dataIndex: "ftpuser", menuDisabled: true},
   					{header: "FTP路径",		dataIndex: "ftppath", menuDisabled: true},
   					{header: "备注",			dataIndex: "remark",menuDisabled: true,id: "remark"}
			],
			buttonAlign: "center",
			bbar: new Ext.ux.PagingToolbar({
   	        	pageSize: limit,
   	        	store: data_store
   	    	}),
			buttons:[{
				text:"新增", 
				handler: function(){
					Ext.getCmp('save').setDisabled(false);
					oper_type = "add";
					Ext.getCmp("p2").resetParam();
					Ext.getCmp("mycontainer").layout.setActiveItem(1);
				}
			},{
				text:"修改", 
				handler: function(){
					Ext.getCmp('save').setDisabled(false);
					var record = Ext.getCmp("p1").getSelectionModel().getSelected();
					if (record){
						Ext.getCmp("p2").setParam(record.data);
						oper_type = "upd";
						Ext.getCmp("mycontainer").layout.setActiveItem(1);
					} else {
						Ext.Msg.show({
	                        title:"警告",
	                        msg: "请先选择一条记录，然后点击修改!",
	                        buttons: Ext.Msg.OK,
	                        animEl: "elId",
	                        icon:Ext.MessageBox.WARNING
                        });
					}
				}
			},{
				text:"删除", 
				handler: function(){
					var record = Ext.getCmp("p1").getSelectionModel().getSelected();
					if(record){
						Ext.Msg.confirm("警告","删除外包商将一并删除该外包商对应的封装计费信息.<br/>确定要删除吗?",function(button) {
							if(button == "yes") {
								var url = "epiboly!del.action";
								var params = {
									"epiboly.id":record.data.id
								};
								oper(url,params);
							}
						});
					} else {
						Ext.Msg.show({
	                        title:"警告",
	                        msg: "请先选择一条记录，然后点击删除!",
	                        buttons: Ext.Msg.OK,
	                        animEl: "elId",
	                        icon:Ext.MessageBox.WARNING
                        });
					}
			}}]
		};
		var p2 = {
			id: "p2",
			xtype: "form",
		    bodyStyle:"padding:5px 5px 0",
			defaultType: "textfield",
			items: [{
				id: "epiboly.id", 
				fieldLabel: "编号",
				name: "epiboly.id",
				anchor: "100%"
			},{
				id: "epiboly.name", 
				fieldLabel: "名称",	
				vtype:"alphanumchinese",
				name: "epiboly.name",
				anchor: "100%",
				validator:function (val){
	        		if(val=="")return "该输入项为必输项！";
	        		if(Ext.fucCheckCHLength(val)>50){
	        			return "请输入50个字符范围内的值！<br>注：一个中文字符算两个字符的长度！";
	        		}
	        		return true;
	        	}
			},{
				id: "epiboly.linkman", 
				fieldLabel: "联系人",	
				vtype:"alphanumchinese",
				name: "epiboly.linkman",
				anchor: "100%",
				validator:function (val){
	        		if(val=="")return true;
	        		if(Ext.fucCheckCHLength(val)>20){
	        			return "请输入20个字符范围内的值！<br>注：一个中文字符算两个字符的长度！";
	        		}
	        		return true;
	        	}
			},{
				id: "epiboly.linkphone", 	  
				fieldLabel: "联系电话",		
				xtype:"numberfield",
				maxLength:20,
				name: "epiboly.linkphone",
				anchor: "100%"
			},{
				id: "epiboly.ftp", 	  
				fieldLabel: "FTP IP地址",	
				allowBlank: false,
				vtype:"ip",
				name: "epiboly.ftp",
				anchor: "100%"
			},{
				id: "epiboly.port",
				xtype:"numberfield",
				fieldLabel: "FTP端口",	
				allowBlank: false,
				name: "epiboly.port",
				anchor: "100%",
				validator: function(val){
					if(!(/^[\d]{1,5}$/).test(val) || parseInt(val) < 1 || parseInt(val) > 65535) {
						return "必须设置为1到65535之间的整数！";
					}
				}
			},{
				id: "epiboly.ftpuser", 	  
				fieldLabel: "FTP用户名",	
				allowBlank: false,
				vtype:"alphanumchinese",
				name: "epiboly.ftpuser",
				anchor: "100%",
				validator:function (val){
	        		if(val=="")return true;
	        		if(Ext.fucCheckCHLength(val)>20){
	        			return "请输入20个字符范围内的值！<br>注：一个中文字符算两个字符的长度！";
	        		}
	        		return true;
	        	}
			},{
				id: "epiboly.ftppass", 	  
				fieldLabel: "FTP密码",	
				vtype:"password",
				allowBlank: false,
				name: "epiboly.ftppass",
				anchor: "100%",
				validator:function (val){
	        		if(val=="")return "该输入项为必输项！";
	        		try {
						if (!/\W/.test(val))
							return true;
						return "请输入英文字母或是数字,其它字符是不允许的.";
					} catch (e) {
						return "请输入英文字母或是数字,其它字符是不允许的.";
					}
	        	}
				
			},{
				id: "repass", 	  
				fieldLabel: "FTP确认密码",
				allowBlank: false,
				vtype:"password",
				name: "repass",
				anchor: "100%",
				validator:function (val){
	        		if(val=="")return "该输入项为必输项！";
	        		try {
						if (!/\W/.test(val))
							return true;
						return "请输入英文字母或是数字,其它字符是不允许的.";
					} catch (e) {
						return "请输入英文字母或是数字,其它字符是不允许的.";
					}
	        	}
			},{
				id: "epiboly.ftppath", 	  
				fieldLabel: "FTP上传路径",	
				allowBlank: false,
				vtype:"maxlength",
				maxLength:100,
				name: "epiboly.ftppath",
				anchor: "100%"
			},{
				id: "epiboly.linkaddr", 	  
				fieldLabel: "联系地址",	
				allowBlank: false,
				vtype:"alphanumchinese",
				validator:function (val){
	        		if(val=="")return "该输入项为必输项！";
	        		if(Ext.fucCheckCHLength(val)>100){
	        			return "请输入100个字符范围内的值！<br>注：一个中文字符算两个字符的长度！";
	        		}
	        		return true;
	        	},
				name: "epiboly.linkaddr",
				anchor: "100%"
			},{
				id: "epiboly.state", 	  
				fieldLabel: "状态",	
				allowBlank: false,
				name: "epiboly.state",
				xtype: "billCombox",
				store: state_store
			},{
				id: "epiboly.remark", 	  
				fieldLabel: "备注",				
				name: "epiboly.remark",
				anchor: "100%",
				vtype:"alphanumchinese",	
				validator:function (val){
	        		if(val=="")return true;
	        		if(Ext.fucCheckCHLength(val)>200){
	        			return "请输入200个字符范围内的值！<br>注：一个中文字符算两个字符的长度！";
	        		}
	        		return true;
	        	}
			}],
			buttonAlign: "center",
			buttons:[{id: 'save', text:"保存", handler: function(e){
				if(!Ext.getCmp("p2").getForm().isValid()){
					Ext.Msg.show({
	   					title:"警告",
	   					msg: "验证不通过!",
	   					buttons: Ext.Msg.OK,
	   					animEl: "elId",
	   					icon:Ext.MessageBox.WARNING
					});
					return;
				}
				var form = this.ownerCt.ownerCt.getForm();
				var id = Ext.getCmp("epiboly.id").getValue();
				var name = Ext.getCmp("epiboly.name").getValue();
				var linkman = Ext.getCmp("epiboly.linkman").getValue();
				var linkphone = Ext.getCmp("epiboly.linkphone").getValue();
				var ftp = Ext.getCmp("epiboly.ftp").getValue();
				var port = Ext.getCmp("epiboly.port").getValue();
				var ftpuser = Ext.getCmp("epiboly.ftpuser").getValue();
				var ftppass = Ext.getCmp("epiboly.ftppass").getValue();
				var ftppath = Ext.getCmp("epiboly.ftppath").getValue();
				var linkaddr = Ext.getCmp("epiboly.linkaddr").getValue();
				var state = Ext.getCmp("epiboly.state").getValue();
				var remark = Ext.getCmp("epiboly.remark").getValue();
				var url,params;
				if(oper_type == "add") {
					url="epiboly!add.action";
				} else if(oper_type == "upd") {
					url="epiboly!upd.action";
				}
				params = {
					"epiboly.id": id,
					"epiboly.name": name,
					"epiboly.linkman": linkman,
					"epiboly.linkphone": linkphone,
					"epiboly.ftp": ftp,
					"epiboly.port": port,
					"epiboly.ftpuser": ftpuser,
					"epiboly.ftppass": ftppass,
					"epiboly.ftppath": ftppath,
					"epiboly.linkaddr": linkaddr,
					"epiboly.state": state,
					"epiboly.remark": remark
				};
				e.setDisabled(true);
				oper(url,params);
			}},{text:"取消", handler: function(){
				Ext.getCmp("mycontainer").layout.setActiveItem(0);
			}
		}],
		setParam: function(data){
			Ext.getCmp("epiboly.id").setValue(data.id);
			Ext.getCmp("epiboly.id").setVisible(true);
			Ext.getCmp("epiboly.id").setDisabled(true);
			Ext.getCmp("epiboly.name").setValue(data.name);
			Ext.getCmp("epiboly.linkman").setValue(data.linkman);
			Ext.getCmp("epiboly.linkphone").setValue(data.linkphone);
			Ext.getCmp("epiboly.ftp").setValue(data.ftp);
			Ext.getCmp("epiboly.port").setValue(data.port);
			Ext.getCmp("epiboly.ftpuser").setValue(data.ftpuser);
			Ext.getCmp("epiboly.ftppass").setValue(data.ftppass);
			Ext.getCmp("repass").setValue(data.ftppass);
			Ext.getCmp("epiboly.ftppath").setValue(data.ftppath);
			Ext.getCmp("epiboly.linkaddr").setValue(data.linkaddr);
			Ext.getCmp("epiboly.state").setValue(data.state);
			Ext.getCmp("epiboly.remark").setValue(data.remark);
		},
		resetParam: function(){
			Ext.getCmp("epiboly.id").setVisible(false);
			Ext.getCmp("epiboly.name").setValue("");
			Ext.getCmp("epiboly.linkman").setValue("");
			Ext.getCmp("epiboly.linkphone").setValue("");
			Ext.getCmp("epiboly.ftp").setValue("");
			Ext.getCmp("epiboly.port").setValue("");
			Ext.getCmp("epiboly.ftpuser").setValue("");
			Ext.getCmp("epiboly.ftppass").setValue("");
			Ext.getCmp("repass").setValue("");
			Ext.getCmp("epiboly.ftppath").setValue("");
			Ext.getCmp("epiboly.linkaddr").setValue("");
			Ext.getCmp("epiboly.state").setValue("");
			Ext.getCmp("epiboly.remark").setValue("");
		}
	};
	
	var info_pel = new Ext.Panel({
		id: "mycontainer", 
		border : false,		
		layout: "card",
		activeItem: 0,
		items: [p1, p2]
	});
	
	data_store.load({params:{start:0,limit:limit}});
	
	var oper = function(url, params){
		Ext.Ajax.request({
			clientValidation: true,
			params: params,
			url: url,
			success: function(response, opts){
				var d=eval("("+response.responseText+")");
				if(d.code == "0"){
					Ext.getCmp("p1").getBottomToolbar().doRefresh();
					if(oper_type == "add") {
						Ext.Msg.show({
		                    title:"提示",
		                    msg:"操作成功!<br/>已添加该外包商的默认封装计费信息.",
		                    buttons:Ext.Msg.OK,
		                    icon: Ext.MessageBox.INFO
	                    });
					} else {
						Ext.Msg.show({
		                    title:"提示",
		                    msg:"操作成功!",
		                    buttons:Ext.Msg.OK,
		                    icon: Ext.MessageBox.INFO
	                    });
                    }
					Ext.getCmp("mycontainer").layout.setActiveItem(0);
				} else {
					Ext.Msg.show({
	                    title:"提示",
	   					msg:"操作失败!",
	   					buttons:Ext.Msg.OK,
	   					icon: Ext.MessageBox.ERROR
					});
				}
                  
                Ext.getCmp("save").setDisabled(false);
			}
		});
	};
		
	var CenterPanel=Ext.getCmp("CenterPanel");
	CenterPanel.removeAll();
	CenterPanel.add(info_pel);
	CenterPanel.doLayout();
</script>